<?php


use App\Http\Controllers\Home\ScreenController;
use Illuminate\Http\Request;
use \App\Services\WebsocketDataService;
use SwooleTW\Http\Websocket\Facades\Websocket;

/*
|--------------------------------------------------------------------------
| Websocket Routes
|--------------------------------------------------------------------------
|
| 在这里，您可以为应用程序注册 websocket 事件。
|
*/

Websocket::on('connect', function ($websocket, Request $request) {
    // called while socket on connect
    dump($websocket->getSender() . '--connect');
    $websocket->emit('message', '服务器连接成功！');
});

Websocket::on('disconnect', function ($websocket) {
    // called while socket on disconnect
    dump($websocket->getSender() . '---disconnect');
    $websocket->emit('message', '服务器连接断开！');
});

Websocket::on('example', function ($websocket, $data) {
    dump('example');
    $websocket->emit('message', $data);
});
Websocket::on('test', function ($websocket, $data) {
    dump('test' . $websocket->getSender());
    $websocket->emit('test', $data);
});
Websocket::on('webconfig', function ($websocket, $data) {
    $config = (new WebsocketDataService())->webConfig();
    dump($config);
    $websocket->emit('webconfig', $config);
});
Websocket::on('getProjectTop', function ($websocket, $data) {
    $getProjectTop = (new WebsocketDataService())->getProjectTop();
    $websocket->emit('getProjectTop', $getProjectTop);
});
Websocket::on('getProjectProgress', function ($websocket, $data) {
    $getProjectProgress = (new WebsocketDataService())->getProjectProgress();
    $websocket->emit('getProjectProgress', $getProjectProgress);
});
Websocket::on('getStatistics', function ($websocket, $data) {
    $getStatistics = (new WebsocketDataService())->getStatistics();
    $websocket->emit('getStatistics', $getStatistics);
});
Websocket::on('Region', function ($websocket, $data) {
    $getStatisticsByRegion = (new WebsocketDataService())->getStatisticsByRegion();
    $websocket->emit('Region', $getStatisticsByRegion);
});
Websocket::on('projectManth', function ($websocket, $data) {
    $getProjectMCount = (new WebsocketDataService())->getProjectMCount();
    $websocket->emit('projectManth', $getProjectMCount);
});
